package com.cxy.instarsystem.web;

import com.cxy.instarsystem.service.DataService;
import com.cxy.instarsystem.service.MCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class DataController {

    @Autowired
    private DataService dataService;

    @Autowired
    private MCategoryService mCategoryService;

    @GetMapping("material")
    public String dataPage(@PageableDefault(size = 18, sort = {"dataorder"}, direction = Sort.Direction.ASC)
                                       Pageable pageable, Model model){
        model.addAttribute("mcategories", mCategoryService.listCategory());
        model.addAttribute("datas", dataService.materialList(pageable,"1"));
        return "download";
    }
    @PostMapping("material")
    public String pageShow(@PageableDefault(size = 18, sort = {"dataorder"}, direction = Sort.Direction.ASC)
                                   Pageable pageable,String value, Model model){
        model.addAttribute("datas", dataService.materialList(pageable,value));
        return "download :: datalist";
    }


}
